//
//  WLDeviceManagerCell.m
//  WanLian
//
//  Created by muzhuang on 2018/10/26.
//  Copyright © 2018年 wanlian. All rights reserved.
//

#import "WLDeviceManagerCell.h"

@implementation WLDeviceManagerCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        _ivHead = [[UIImageView alloc] initWithFrame:CGRectMake(16, (WLScaleX(80)-38)/2.0, 46, 38)];
        _ivHead.image = [UIImage imageNamed:@"router_device"];
        [self.contentView addSubview:_ivHead];
        
        _labTitle = [[UILabel alloc] init];
        _labTitle.font = [WLCommonTool fontTypePingFangSCMedium:17];
        _labTitle.textColor = wlBlackColor;
        [self.contentView addSubview:_labTitle];
        
        _labDetail = [[UILabel alloc] init];
        _labDetail.font = [WLCommonTool fontTypePingFangSCRegular:11];
        _labDetail.textColor = wlDarkGrayColor;
        [self.contentView addSubview:_labDetail];
        
        _labStatus = [[UILabel alloc] init];
        _labStatus.font = [WLCommonTool fontTypePingFangSCRegular:12];
        _labStatus.textColor = wlGreenColor;//wlLightTextColor;
        _labStatus.text = @"在线";
        _labStatus.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:_labStatus];
        
        _labBlack = [[UILabel alloc] init];
        _labBlack.backgroundColor = wlDarkGrayColor;
        _labBlack.font = [WLCommonTool fontTypePingFangSCRegular:8];
        _labBlack.textColor = [UIColor whiteColor];
        _labBlack.text = @"黑名单";
        _labBlack.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:_labBlack];
        _labBlack.layer.cornerRadius = 2;
        _labBlack.layer.masksToBounds = YES;
        
//        _labNetwork = [[UILabel alloc] init];
//        _labNetwork.font = [WLCommonTool fontTypePingFangSCRegular:12];
//        _labNetwork.textColor = wlDarkGrayColor;
//        _labNetwork.textAlignment = NSTextAlignmentCenter;
//        [self.contentView addSubview:_labNetwork];
//        _labNetwork.layer.cornerRadius = 5;
//        _labNetwork.layer.masksToBounds = YES;
//        _labNetwork.layer.borderWidth = 1;
//        _labNetwork.layer.borderColor = wlDarkGrayColor.CGColor;
        
        _labTime = [[UILabel alloc] init];
        _labTime.font = [WLCommonTool fontTypePingFangSCRegular:12];
        _labTime.textColor = wlLightTextColor;
        [self.contentView addSubview:_labTime];
        
    }
    return self;
}

- (void)setRouterDevices:(WLRouterDeviceModel *)routerDevices
{
    _routerDevices = routerDevices;
    _labTitle.text = routerDevices.name;
    _labDetail.text = [NSString stringWithFormat:@"MAC:%@",routerDevices.macAddress];
    if (routerDevices.access) {
        _labBlack.alpha = 0;
    }
    else
    {
        _labBlack.alpha = 1.0;
    }
    _labTime.text = [WLCommonTool strToLoginTime:routerDevices.loginTime];
    
    [self layoutIfNeeded];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    WLWkSelf
    CGFloat widthTitle;
    if (_routerDevices.access) {
        CGSize size = [_labTitle.text boundingRectWithSize:CGSizeMake(WIDTH_SCREEN_WL-16-46-10-32-15, 24) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : [WLCommonTool fontTypePingFangSCMedium:17]} context:nil].size;
        if (size.width >= WIDTH_SCREEN_WL-16-46-10-32-15) {
            widthTitle = WIDTH_SCREEN_WL-16-46-10-32-15+2.0;
        }
        else
        {
            widthTitle = size.width+2.0;
        }
    }
    else
    {
        CGSize size = [_labTitle.text boundingRectWithSize:CGSizeMake(WIDTH_SCREEN_WL-16-46-10-32-36-15, 24) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : [WLCommonTool fontTypePingFangSCMedium:17]} context:nil].size;
        if (size.width >= WIDTH_SCREEN_WL-16-46-10-32-36-15)
        {
            widthTitle = WIDTH_SCREEN_WL-16-46-10-32-36-15+2.0;
        }
        else
        {
            widthTitle = size.width+2.0;
        }
        
        [_labBlack mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.labStatus.mas_right);//.offset(5);
            make.size.mas_equalTo(CGSizeMake(36, 12));
            make.centerY.equalTo(weakSelf.labStatus.mas_centerY);
        }];
    }
    
    [_labTitle mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.ivHead.mas_right).offset(10);
        make.top.equalTo(weakSelf.ivHead.mas_top).offset(-3);
        make.width.equalTo(@(widthTitle));
        make.height.equalTo(@(24));
    }];
    
    [_labStatus mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.labTitle.mas_right);
        make.top.equalTo(weakSelf.labTitle.mas_top);
//        make.height.equalTo(weakSelf.labTitle.mas_height);
        make.size.mas_equalTo(CGSizeMake(32, 24));
    }];
    
    [_labBlack mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.labStatus.mas_right);
        make.size.mas_equalTo(CGSizeMake(36, 12));
        make.centerY.equalTo(weakSelf.labStatus.mas_centerY);
    }];
    
    [_labDetail mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.labTitle.mas_left);
        make.top.equalTo(weakSelf.labTitle.mas_bottom);
        make.height.equalTo(@(20));
    }];
    
//    CGFloat widthAct = [_labNetwork.text boundingRectWithSize:CGSizeMake(120, 22) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName : [WLCommonTool fontTypePingFangSCRegular:12]} context:nil].size.width;
//    [_labNetwork mas_remakeConstraints:^(MASConstraintMaker *make) {
//        make.right.equalTo(weakSelf.contentView.mas_right).offset(-WLScaleX(16));
//        make.centerY.equalTo(weakSelf.labTitle.mas_centerY);
//        make.size.mas_equalTo(CGSizeMake(widthAct+10, 22));
////        make.height.equalTo(@(WLScaleX(22)));
//    }];
    
    [_labTime mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(weakSelf.contentView.mas_right).offset(-15);
        make.top.equalTo(weakSelf.labDetail.mas_top);
        make.height.equalTo(@(20));
    }];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
